package com.kuzlak.cms.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuzlak.cms.bean.MyPage;
import com.kuzlak.cms.module.sys.entity.SysException;
import com.kuzlak.cms.module.sys.mapper.SysExceptionMapper;
import com.kuzlak.cms.module.sys.service.SysExceptionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* @author hesenjan
* @description 针对表【sys_exception】的数据库操作Service实现
* @createDate 2024-11-30 23:46:05
*/
@Service
public class SysExceptionServiceImpl extends ServiceImpl<SysExceptionMapper, SysException>
    implements SysExceptionService{

    @Override
    public MyPage findByPage(int pagesize, int page, String startDate, String endDate, String name, String messeges, String packageName, String code, String userName) {
        MyPage page1 = new MyPage();
        QueryWrapper<SysException> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("ID");

        if (StringUtils.isNotEmpty(name)) {
            queryWrapper.lambda().likeRight(SysException::getName, name);
        }

        if (StringUtils.isNotEmpty(messeges)) {
            queryWrapper.lambda().likeRight(SysException::getMesseges, messeges);
        }

        if (StringUtils.isNotEmpty(packageName)) {
            queryWrapper.lambda().likeRight(SysException::getPackageName, packageName);
        }

        if (StringUtils.isNotEmpty(code)) {
            queryWrapper.lambda().likeRight(SysException::getCode, code);
        }
        if (StringUtils.isNotEmpty(userName)) {
          //  queryWrapper.lambda().inSql(SysException::getUserId, PermissionSqlModel.likeUserName(userName));
        }
        if (StringUtils.isNotEmpty(startDate)) {
            queryWrapper.apply(StringUtils.isNotBlank(startDate), "DATE(DATE)>=DATE_FORMAT('" + startDate + "','%Y-%m-%d')");
        }

        if (StringUtils.isNotEmpty(endDate)) {
            queryWrapper.apply(StringUtils.isNotBlank(endDate), "DATE(DATE)<=DATE_FORMAT('" + endDate + "','%Y-%m-%d')");
        }


        Page<Map<String, Object>> page0 = new Page<>(page, pagesize);
        //   IPage<SysException> data = this.getBaseMapper().selectPage(page0, queryWrapper);
        IPage<Map<String, Object>> data = this.baseMapper.selectMapsPage(page0, queryWrapper);
     return  MyPage.parsePage(data);
    }
}



